#!/bin/bash
#
# Make a pretty(?) index page of the PDF docs.
#

set -e

# Assume we're running in src/, we can't call `git rev-parse
# --show-toplevel` because when building from dsc we don't have a
# git repo.
TOPLEVEL=${PWD}/..
cd "${TOPLEVEL}"/docs

TITLE="LinuxCNC PDF docs ($(cat "${TOPLEVEL}"/VERSION))"

rm -f index.html

{
    echo "<html>"
    echo "<head><title>${TITLE}</title></head>"
    echo "<body><h1>${TITLE}</h1><p>"
} >> index.html

for F in $(ls -1 ./*.pdf | sort); do
    echo "    <a href=\"${F}\">$F</a><br>" >> index.html
done

{
    echo "</body>"
    echo "</html>"
} >> index.html
